package cn.gglol.code.generator;

import java.util.ArrayList;
import java.util.List;

/**
 * 错误日志栈
 *
 * @author <a href='Jvvtao:jwtao520@qq.com'>Jvvtao<a/>
 * @since
 */
public class ErrorStack {
    private List<String> list = new ArrayList<>();

    public void add(String text) {
        list.add(text);
    }

    public void clear() {
        list.clear();
    }

    public boolean isNotEmpty() {
        return !isEmpty();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    public void tryThrow() {
        if (isNotEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (String s : list) {
                sb.append("\n\t").append(s);
            }
            throw new RuntimeException(sb.toString());
        }
    }
}
